package day5;

/**
 * @author oldliu
 * @since 1.0
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] ar = {8, 5, 3, 12, 14, 22, 556, 159, 6, 9};
        System.out.println("排序前：");
        for (int k:ar)
            System.out.print(k+" ");
        System.out.println();
        //外层控制几轮
        //升序
        int temp;
        for (int i = 0; i < ar.length-1; i++) {
            for (int j = 0; j <ar.length-1-i ; j++) {
                if(ar[j]>ar[j+1]){
                    temp=ar[j];
                    ar[j]=ar[j+1];
                    ar[j+1]=temp;
                }
            }
        }
        System.out.println("排序后：");
        for (int k:ar)
            System.out.print(k+" ");
        System.out.println();
    }
}
